package models

import (
	"github.com/astaxie/beego/orm"
	"time"
)
import _ "github.com/go-sql-driver/mysql"

type User struct {
	Id       int
	Username string
	Password string
	Article  []*Article `orm:"rel(m2m)"`
}

type Article struct {
	Id          int          `orm:"pk;auto"`
	Title       string       `orm:"size(30)"`
	Content     string       `orm:"size(500)"`
	Img         string       `orm:"size(200);null"`
	Time        time.Time    `orm:"type(datetime);auto_now_add"`
	Count       int          `orm:"default(0)"`
	ArticleType *ArticleType `orm:"rel(fk)"` //外键
	User        []*User      `orm:"reverse(many)"`
}

type ArticleType struct {
	Id      int
	Title   string     `orm:"size(20)"`
	Article []*Article `orm:"reverse(many)"` //多类型
}

func init() {
	orm.RegisterDataBase("default", "mysql", "root:123456@(192.168.88.137)/books")
	orm.RegisterModel(new(User), new(Article), new(ArticleType))
	orm.RunSyncdb("default", false, true)
}
